﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Settings;

namespace PanasonicWarranty.Business
{
    public partial class pa_WarrantyStatus
    {
        public static List<pa_WarrantyStatus> Paging(int currentPage, int pageSize, ref int totalRecord)
        {
            using (var context = new DBWarrantyDataContext(AppSetting.ConnectionString))
            {
                var resutl = context.pa_WarrantyStatus.AsQueryable();
                totalRecord = resutl.Count();
                return resutl.Skip(((currentPage - 1) < 0 ? 0 : (currentPage - 1)) * pageSize).Take(pageSize).ToList();
            }
        }

        public static pa_WarrantyStatus GetByCode(string code)
        {
            using (var context = new DBWarrantyDataContext(AppSetting.ConnectionString))
            {
                pa_WarrantyStatus retValue = context.pa_WarrantyStatus.FirstOrDefault(p => p.WarrantyStatusCode == code);
                if (retValue == null)
                {
                    retValue = new pa_WarrantyStatus()
                    {
                        WarrantyStatusCode = code,
                        Disabled = false
                    };
                    context.pa_WarrantyStatus.InsertOnSubmit(retValue);
                    context.SubmitChanges();
                }
                return retValue;
            }
        }
    }
}
